package cn.qlu.yhy.dao.mybatisImp;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cn.qlu.yhy.dao.IBookDao;
import cn.qlu.yhy.model.Book;
import cn.qlu.yhy.model.Page;
import cn.qlu.yhy.model.enumpack.BookClassify;
import cn.qlu.yhy.model.enumpack.BookType;

@Component
public class BookDaoImpl implements IBookDao {

    @Autowired
    private SqlSessionTemplate sst;

    private static final String CLASS_NAME = Book.class.getName();

    //    @Override
    //    public int createBook(Book book) {
    //        return sst.insert(CLASS_NAME+ ".createBook", book);
    //    }
    //
    //    public int updateExamId(String id, String examId) {
    //        Map<String, String> params = new HashMap<String, String>();
    //
    //        System.out.println("id " + id + " EXAMId " + examId);
    //
    //        params.put("examId", examId);
    //        params.put("id", id);
    //
    //        return sst.update(CLASS_NAME + ".updateExamId", params);
    //    }
    //
    //    public List<Question> findRandomQuestion(int quantity) {
    //        return sst.selectList(CLASS_NAME + ".findRandomQuestion", quantity);
    //    }
    //
    //    public int insertQuestion2Exam(int examId, int questionId) {
    //        Map<String, Object> params = new HashMap<String, Object>();
    //        params.put("examId", examId);
    //        params.put("questionId", questionId);
    //
    //        return sst.insert(CLASS_NAME + ".insertQuestion2Exam", params);
    //    }
    //
    //    public int insertQuestion2CopyQuestion(Question question) {
    //        return sst.insert(CLASS_NAME + ".insertQuestion2CopyQuestion", question);
    //    }

    @Override
    public boolean createBook(Book book) {
        return sst.insert(CLASS_NAME+ ".createBook", book) > 0 ? true : false;
    }

    @Override
    public List<Book> findBooksAllByUserId(int userId, Page page) {
        // TODO Auto-generated method stub
    	Map<String, Object> params = new HashMap<String, Object>();
    	params.put("userId", userId);
    	params.put("pageSize", page.getPageSize());
    	params.put("currentPage", page.getCurrentPage() - 1);

        return sst.selectList(CLASS_NAME+ ".findBooksAllByUserId", params);
    }

    @Override
    public boolean deleteBook(int bookId) {
    	return sst.delete(CLASS_NAME+ ".deleteBook", bookId) > 0 ? true : false;
    }

    @Override
    public boolean updateBook(Book book) {
        // TODO Auto-generated method stub update
        return sst.update(CLASS_NAME+ ".updateBook", book) > 0 ? true : false;
    }

    @Override
    public Book getBookByBookId(int bookId) {
        // TODO Auto-generated method stub
        return sst.selectOne(CLASS_NAME+ ".getBookByBookId", bookId);
    }

    @Override
    public List<Book> findBooksByBookNAP(String bookNAP) {
    	return sst.selectList(CLASS_NAME+ ".findBooksByBookNAP", bookNAP);
    }

    @Override
    public List<Book> findBooksAll() {
        // TODO Auto-generated method stub
        return null;
    }






    @Override
    public List<Book> findBooksByBookType(BookType bookType) {
        // TODO Auto-generated method stub
        return null;
    }


    @Override
    public List<Book> findBooksByBookClassify(BookClassify bookClassify) {
        // TODO Auto-generated method stub
        return null;
    }


    @Override
    public List<Book> findBooksByAuthor(String author) {
        // TODO Auto-generated method stub
        return null;
    }


    @Override
    public List<Book> findBooksByPress(String press) {
        // TODO Auto-generated method stub
        return null;
    }


    @Override
    public List<Book> findBooksByDescription(String description) {
        // TODO Auto-generated method stub
        return null;
    }


    @Override
    public List<Book> findBooksByCreateDate(Date startDate, Date endDate) {
        // TODO Auto-generated method stub
        return null;
    }

}
